#!/bin/bash
codeSrcPath=$1
echo $codeSrcPath
# node_modules path
nodeModulesPath=${codeSrcPath}/node_modules
# 1. 代码路径
if [[ -d "$codeSrcPath" ]]; then
    cd $codeSrcPath
else
  echo '$codeSrcPath not exists'
  exit 2
fi

# 2. 判断是否需要执行 npm install
echo $nodeModulesPath
if [[ ! -d $nodeModulesPath ]]; then
  npm install
  if [ $? -eq 0 ]; then
    echo "npm install success"
  else
    echo "npm install fail"
    exit 2
  fi
fi

# 3. 执行编译
npm run build
if [ $? -eq 0 ]; then
  echo "npm run build success"
  exit 0
else
  echo "npm run build fail"
  exit 2
fi

